using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SnakeGroundFollow : MonoBehaviour {
	
	public List<Transform> transforms = new List<Transform>();
	public Traverse myTraverse;
	public float heightAboveGround = 0.1f;
	public LayerMask mask;

	// Use this for initialization
	void Start () {	
		myTraverse.each(delegate(GameObject obj) {
			transforms.Add(obj.transform);
			return false;
		});
	}	
	// Update is called once per frame
	void Update () {
		foreach(Transform t in transforms){
			findY (t);
		}
	}
	
	void findY(Transform t)
	{
		Ray ray = new Ray(new Vector3(t.position.x,t.position.y+5,t.position.z),Vector3.down);
		RaycastHit hit = new RaycastHit();
		
		if(Physics.Raycast(ray,out hit,5000f,mask))	{
			Vector3 temp = t.position;
			
			temp.y = hit.point.y+heightAboveGround;
			t.position = temp;
		}
	}
}
